//
//  YDBarrageWalkBannerCell.m
//  YDOCBarrage_Example
//
//  Created by 赵宏亚 on 2019/12/5.
//  Copyright © 2019 Arthur. All rights reserved.
//

#define ImageWidth 26.0

#import "YDBarrageWalkBannerCell.h"

@implementation YDBarrageWalkBannerCell

- (instancetype)init {
    self = [super init];
    if (self) {
        [self addSubviews];
        self.userInteractionEnabled = NO;
    }
    
    return self;
}

- (void)prepareForReuse {
    [super prepareForReuse];
    
    //因为在点击的时候被改为了红色, 所以在重用的时候, 要重置一下颜色
    self.textLabel.backgroundColor = [UIColor clearColor];
}

- (void)addSubviews {
    [self addSubview:self.blackView];
    [self addSubview:self.leftImageView];
}

// MARK: 在这里对元素进行赋值
- (void)updateSubviewsData {
    [super updateSubviewsData];
    [self.leftImageView setImage:[UIImage imageNamed:@"chaoren_left"]];
}

// MARK: 设置子视图的大小和位置
- (void)layoutContentSubviews {
    [super layoutContentSubviews];
    
    NSLog(@"bannerLeftImageSrc **** %@",self.walkBannerDescriptor.bannerLeftImageSrc);
    
    self.leftImageView.frame = CGRectMake(2.0, 2.0, ImageWidth, ImageWidth);
    self.textLabel.frame = CGRectMake(CGRectGetMaxX(self.leftImageView.frame)+12, (ImageWidth-self.textLabel.bounds.size.height)/2.0+2, self.textLabel.bounds.size.width, self.textLabel.bounds.size.height);
    self.blackView.frame = CGRectMake(0, 0, CGRectGetMaxX(self.textLabel.frame)+17, ImageWidth+4);
}

- (void)convertContentToImage {
    UIImage *contentImage = [self.layer convertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.rightImageView.frame), CGRectGetMaxY(self.rightImageView.frame))];
    [self.layer setContents:(__bridge id)contentImage.CGImage];
}

- (void)removeSubViewsAndSublayers {
    //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了.
    //比如: 你想在这个cell被点击的时候, 修改文本颜色
}

#pragma mark ---- setter
- (void)setBarrageDescriptor:(OCBarrageDescriptor *)barrageDescriptor {
    [super setBarrageDescriptor:barrageDescriptor];
    self.walkBannerDescriptor = (YDBarrageWalkBannerDescriptor *)barrageDescriptor;
}

#pragma mark ---- getter
- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc] init];
        _leftImageView.contentMode = UIViewContentModeScaleAspectFit;
        _leftImageView.layer.masksToBounds = YES;
        _leftImageView.layer.cornerRadius = 13;
        _leftImageView.layer.borderColor = UIColor.whiteColor.CGColor;
        _leftImageView.layer.borderWidth = 0.5;
    }
    return _leftImageView;
}

- (UIView *)blackView {
    if (!_blackView) {
        _blackView = [[UIView alloc] init];
        _blackView.backgroundColor = UIColor.blackColor;
        _blackView.alpha = 0.45;
        _blackView.layer.masksToBounds = YES;
        _blackView.layer.cornerRadius = 15;
    }
    return _blackView;
}

@end
